/*
 * @# Templates.java 2011-11-4 上午10:16:51
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司
 * Guangzhou ianswer information technology co. ltd.
 * 
 * All rights reserved!
 */
package com.ianswer.experiments.templates;

import java.io.IOException;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

import com.ianswer.common.util.PropertiesUtils;

/**
 * @author alvin hwang
 */
public final class Templates {

	private static final String DEFAULT_TEMPLATE = "default";

	public static String getTemplate(String user) throws IOException {
		if (StringUtils.isBlank(user)) {
			return getDefaultTemplate();
		}
		Properties properties = PropertiesUtils.loadProperties("templates.properties");
		String templateName = properties.getProperty("users." + user);
		if (StringUtils.isBlank(templateName)) {
			return getDefaultTemplate();
		}
		String template = properties.getProperty("templates." + templateName);
		return StringUtils.isBlank(template) ? getDefaultTemplate() : template;
	}

	public static String getDefaultTemplate() throws IOException {
		Properties properties = PropertiesUtils.loadProperties("templates.properties");
		return properties.getProperty("templates." + DEFAULT_TEMPLATE);
	}
}
